package org.example.laboratorymanagement.controller;


import lombok.extern.slf4j.Slf4j;
import org.example.laboratorymanagement.pojo.PageBean;
import org.example.laboratorymanagement.pojo.Plan;
import org.example.laboratorymanagement.pojo.Result;
import org.example.laboratorymanagement.service.PlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@Slf4j
@RequestMapping("/plans")
@RestController
public class PlanController {

    @Autowired
    private PlanService planService;

    @GetMapping
    public Result listTeachers(@RequestParam(defaultValue = "1") Integer page,
                               @RequestParam(defaultValue = "10") Integer pageSize,
                               String username, String experiment, String local,
                               @DateTimeFormat(pattern = "yyyy-MM-dd") String date,
                               String time) {
        log.info("模糊查询实验计划，参数：{},{},{},{},{},{},{}",page,pageSize, username, experiment, local, date, time);

        PageBean pageBean = planService.pagePlans(page, pageSize, username, experiment, local, date, time);

        return Result.success(pageBean);
    }

    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        log.info("批量删除实验计划ID操作，ids：{}",ids);
        planService.delete(ids);
        return Result.success();

    }

    @PutMapping
    public Result update(@RequestBody Plan plan){
        log.info("修改实验计划：{}",plan);

        planService.update(plan);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody Plan plan){
        log.info("新增实验计划：{}",plan);
        planService.add(plan);
        return Result.success();
    }


}
